package P150;

/**
 * @author LiangMu
 * @version \$Id: P17.java, v 0.1, 2024年07月04日 18:39 LiangMu Exp $$
 */
public class P17 {

    public String intToRoman(int num) {
        int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        String[] symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        int temp = num;
        StringBuilder ans = new StringBuilder();

        for (int index = 0; index < values.length; index++) {
            int value = values[index];
            while (temp >= value) {
                ans.append(symbols[index]);
                temp -= value;
            }
        }
        return ans.toString();
    }

}
